<template>
	<view class="container">
		<view class="card-tip">提现银行卡</view>
		<uni-card v-if="!showAddCard">
			<view class="bank-header">
				<view class="bank-name">{{bankInfo.bankName}}</view>
				<uni-icons type="trash-filled" size="30" color="#73f201" @click="delCard"></uni-icons>
			</view>
			<view class="line"></view>
			<view class="card-info">
				<view class="card-item">
					<view class="card-tishi">持卡人</view>
					<view class="card-content">{{bankInfo.name}}</view>
				</view>
				<view class="card-item">
					<view class="card-tishi">银行预留手机号</view>
					<view class="card-content">{{bankInfo.phone}}</view>
				</view>

			</view>
			<view class="card-info">
				<view class="card-item">
					<view class="card-tishi">银行卡号</view>
					<view class="card-content">{{bankInfo.bankCardNo}}</view>
				</view>
			</view>
		</uni-card>
		<uni-card v-else>
			<view class="add-card" @click="addCard">
				<uni-icons type="plusempty" size="40" color="#c8bfbf"></uni-icons>
				<view class="add-card-text">添加银行卡</view>
			</view>
		</uni-card>

	</view>
</template>

<script>
	import {
		getShopBankCard,
		delShopBankCard
	} from '@/api/shops/cashout/cashout.js'
	export default {
		data() {
			return {
				bankInfo: {
					bankName: '',
					bankCardNo: '',
					name: '',
					phone: '',
				},
				showAddCard:false,
				shopId:''
			}
		},
		onLoad:function(option) {
			this.shopId = option.shopId
			this.init()
		},
		watch:{
			'bankInfo.name' (val) {
				this.showAddCard = (val == undefined || val.name == '')
			},
			immediate:true // watch侦听操作内的函数会立刻被执行
		},
		methods: {
			init() {
				getShopBankCard(this.shopId).then((res) => {
					
						this.bankInfo = res
					
				})
			},
			delCard() {
				let _this = this
				uni.showModal({
					title: '删除银行卡',
					success: function(rs) {
						if (rs.confirm) {
							delShopBankCard(_this.shopId).then((res) => {
								
									_this.bankInfo = {}
								
							})
						}
					}
				})
			},
			addCard() {
				let _this = this
				uni.navigateTo({
					url: `/subpkg/shops/bindBankCard/bindBankCard?shopId=${_this.shopId}`,
					events: {
						bankCardManageEvent(data) {
							if (data.data) {
								_this.init()
							}
						}
					},
					success: function(res) {
						res.eventChannel.emit('eventName', {
							data: 'bankCardManageEvent'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.card-tip {
		font-size: 18px;
		font-weight: bold;
		margin: 10px 0 10px 10px;
	}

	.bank-header {
		display: flex;
		flex-direction: row;
		justify-content: space-between;

		.bank-name {
			font-size: 16px;
			font-weight: bold;
		}
	}

	.line {
		border-bottom: 1px solid #bcbcbc;
		margin: 5px 0;
	}

	.card-info {
		display: flex;
		flex-direction: row;
		// justify-content: space-between;
		align-items: flex-start;
		margin: 10px 0;

		.card-item {
			flex: 1;

			.card-tishi {
				font-size: 13px;
				font-weight: bold;
				color: #c8bfbf;
			}

			.card-content {
				font-size: 16px;
				font-weight: bold;
				color: #000;
			}
		}
	}

	.add-card {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 50px 0;
		color: #c8bfbf;
	}
</style>